package controller.api;
import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.tx.Tx;

import common.inter.StaffStationInter;
import model.CompareCheck;
import model.CompareCheckGroup;
import service.CompareCheckService;

public class ApiCompareCheckController extends BaseApiController {
	@Inject CompareCheckService compareCheckService ;

	public void list() {
	    Kv kv = getParamKv() ;
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", compareCheckService.getApiPage( kv , pageNumber, pageSize));
	    renderJson();
	}
	
	@Before({StaffStationInter.class,Tx.class})
	public void save() {
		try {
			List<CompareCheck> list = getModelList(CompareCheck.class);
			CompareCheckGroup checkGroup = getModel(CompareCheckGroup.class,"",true);
			renderJson( compareCheckService.save( list , checkGroup , getStaff() , getStation() ) );
		} catch (Exception e) {
			e.printStackTrace();
			renderFail(e.getMessage());
			throw e ;
		}
	}
}
